<template>
	<view class="uni_box home">
		<navbar title='填写举报内容'>
		</navbar>
		<view class="content">
			<text class="jname">建议上传可证明举报内容的图片</text>
			<view class="chuantu">
				<view class="tuview">
					<!-- <view class="tuitem">
						<image class="icon_zp" src="@/pages_client/static/img/img_sp.png" mode="" />
						<text>上传视频</text>
					</view> -->
					<view class="tuitem"  @click="upload(1)" v-if="!images">
						<image class="icon_zp" src="@/pages_client/static/img/icon_zp.png" mode="" />
						<text>上传照片</text>
					</view>
					<view class="tuitem tuchuan" @click="upload(1)" v-if="images">
						<image class="icon_zp" :src="images" mode="" />
					</view>
				</view>
			</view>
			<view class="mshu">
				<u-input class="iteminput" v-model="msg" type="textarea" :border="false" placeholder='输入问题内容(必填)' />
			</view>
			<view class="tijiao" @click="gettijiao">提交</view>
		</view>
	</view>
</template>

<script>
import {
		baseUrl
	} from '@/utils/config.js'; 
	export default {
		data() {
			return {
				msg:'',
				htype:1,
				head_portrait:'',
				images:'',
				id:'',
				video:''
			}
		},
		onLoad(option) {
			if(option.id){
				this.id = option.id
			}
		},
		onShow() {
		},
		methods: {
			upload(e) {
				this.htype = e
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.head_portrait = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
					}
				});
			},
			unloadtou() {
				// console.log(this.head_portrait)
				let that = this
				uni.uploadFile({
					url: baseUrl + '/api/common/upload', //仅为示例，非真实的接口地址
					filePath: this.head_portrait,
					name: 'file',
					header: {
						'token': uni.getStorageSync('token'),
					},
					formData: {
						'token':uni.getStorageSync('token'),
					},
					success: (uploadFileRes) => {
						// console.log(uploadFileRes)
						console.log(JSON.parse(uploadFileRes.data).data.url);//url

						that.images = (JSON.parse(uploadFileRes.data).data.url)
					}
				});
			},
			async gettijiao(){
				if(!this.msg){
					this.$u.toast("输入问题内容");
					return;
				}
				let res = await this.$u.api.report({
					images:this.images,
					video:this.video,
					msg:this.msg,
					id:this.id
				});
				this.$u.toast("操作成功");
				this.images = ''
				this.msg = ''
				this.video = ''
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.jname{
		font-weight: 500;
		font-size: 32rpx;
		color: #111111;
		display: block;
		margin-bottom: 20rpx;
	}
	.content{
		background-color: #fff;
		padding: 30rpx;
		min-height: 100vh;

		.list{
			margin-bottom: 30rpx;
			.item{
				background: rgba(248, 248, 248, 1);
				border-radius: 20rpx;
				padding: 30rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				.iname{
					max-width: 80%;
					display: inline-block;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
				}
				.icon_ck_sxia{
					width: 24rpx;
					height: 24rpx;
					margin-left: auto;
				}
			}
			.daan{
				background: #FFF8F5;
				border-radius:0 0 20rpx 20rpx;
				padding: 30rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #FF773D;
			}
		}
		.iszhan{
			.item{
				border-radius:20rpx 20rpx 0 0 ;
			}
		}
	}
	.chuantu{
		margin-top: 20rpx;
	}
	.chuanmiao{
		display: block;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.tuview{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		.tuitem{
			margin: 0 30rpx 0 0;
			width: 160rpx;
			height: 160rpx;
			background: #F8F8F8;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			position: relative;
			.icon_zp{
				width: 56rpx;
				height: 56rpx;
				margin-bottom: 20rpx;
			}
			text{
				font-weight: 500;
				font-size: 26rpx;
				color: #333333;
			}
		}
		.tuchuan{
			.icon_zp{
				position: absolute;
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
				margin-bottom: 0;
			}
		}
	}
	.mshu{
		padding:20rpx 30rpx;
		background: #F8F8F8;
		border-radius: 20rpx;
		margin-bottom: 100rpx;
		margin-top: 30rpx;
	}
	.tijiao{
		height: 90rpx;
		background: linear-gradient(90deg, #FF8F39, #FF4D43);
		border-radius: 45rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: bold;
		font-size: 28rpx;
		color: #FFFFFF;
	}
</style>
